﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data ;
using System.Data .SqlClient ;
using dhDataAcess.dataAcess .sysDataSetTableAdapters ;
using dhDataAcess.Model ;

namespace dhDataAcess.sysDAL
{
  public class modulAaccessDAL
    {
      string tableName = "modulAaccess";
         private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public modulAaccessDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction;
            conn=_conn;
        }
      
        /// <summary>
        /// 插入一行模块表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int modulAaccessInsert(modulAaccessModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertStr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            //string insertStr = "insert into modulAaccess (mark,updateUser,updateDate,createUser,createDate,importAc,printAc,exportAc,delAc,editAc,addAc,showAc,moduleNum,groupNum) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@importAc,@printAc,@exportAc,@delAc,@editAc,@addAc,@showAc,@moduleNum,@groupNum)";
            SqlParameter[] para = {
                                  new SqlParameter ("@mark",deptRow .mark ),
                                  new SqlParameter ("@updateUser",deptRow .updateUser ),
                                  new SqlParameter ("@updateDate",deptRow .updateDate),
                                  new SqlParameter ("@createUser",deptRow .createUser),
                                  new SqlParameter ("@createDate",deptRow .createDate),
                                  new SqlParameter ("@importAc",deptRow .importAc ),
                                  new SqlParameter ("@printAc",deptRow .printAc ),
                                  new SqlParameter ("@exportAc",deptRow .exportAc ),
                                  new SqlParameter ("@delAc",deptRow .delAc),
                                  new SqlParameter ("@editAc",deptRow .editAc ),
                                  new SqlParameter ("@addAc",deptRow .addAc ),
                                  new SqlParameter ("@showAc",deptRow .showAc ),
                                  new SqlParameter ("@moduleNum",deptRow .moduleNum),
                                  new SqlParameter ("@groupNum",deptRow .groupNum ),
                                  new SqlParameter ("@checkAc",deptRow .checkAc  )
                                  };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 更新一行模块表数据 
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int modulAaccessUpdate(modulAaccessModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updateStr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
           // string updateStr = "update modulAaccess set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,createUser=@createUser,createDate=@createDate,importAc=@importAc,printAc=@printAc,exportAc=@exportAc,delAc=@delAc,editAc=@editAc,addAc=@addAc,showAc=@showAc,groupNum=@groupNum where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                  new SqlParameter ("@recordid",deptRow .recordid ),
                                  new SqlParameter ("@mark",deptRow .mark ),
                                  new SqlParameter ("@updateUser",deptRow .updateUser ),
                                  new SqlParameter ("@updateDate",deptRow .updateDate),
                                  new SqlParameter ("@createUser",deptRow .createUser),
                                  new SqlParameter ("@createDate",deptRow .createDate),
                                  new SqlParameter ("@importAc",deptRow .importAc ),
                                  new SqlParameter ("@printAc",deptRow .printAc ),
                                  new SqlParameter ("@exportAc",deptRow .exportAc ),
                                  new SqlParameter ("@delAc",deptRow .delAc),
                                  new SqlParameter ("@editAc",deptRow .editAc ),
                                  new SqlParameter ("@addAc",deptRow .addAc ),
                                  new SqlParameter ("@showAc",deptRow .showAc ),
                                  new SqlParameter ("@moduleNum",deptRow .moduleNum),
                                  new SqlParameter ("@groupNum",deptRow .groupNum ),
                                    new SqlParameter ("@checkAc",deptRow .checkAc  )
                                  };
           
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updateStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }


        /// <summary>
        /// 删除一行模块表数据
        /// </summary>
        /// <param name="moduleNum"></param>
        /// <returns></returns>

        public int modulAaccessDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deleteStr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
            //string deleteStr = "delete modulAaccess where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                new SqlParameter ("@recordid",recordid)
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = deleteStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        
    }
}
